//导入库
import { world, Player } from "@minecraft/server";
import { ActionFormData } from "@minecraft/server-ui";
import { config } from "./config";

//玩家加入事件
world.afterEvents.playerJoin.subscribe(i => {
    if (!i.player.hasTag("player")){
        NewPlayerMenu(i.playerName)
        NewPlayerEvent(i.sender)
        i.player.addTag("player")
    }
})
//新玩家加入
function NewPlayerEvent(player) {
    player.runCommandAsync("scoreboard players add 注册人数 uid 1")
    player.runCommandAsync("scoreboard players operation @s uid = 注册人数 uid")
    player.runCommandAsync("structure load 新手装备 ~~~")
}

//UI表单
function NewPlayerMenu(player) {
    const UI = new ActionFormData()
        .title(`§6______§f欢迎来到 ${config.text.ServerName} §6______§r`)
        .body(config.text.Introduction)
        .button(`常用命令`)
        .button(`关于本服`)
        .button(`关闭表单`)
        .show(player)
        .then((UI) => {
            if (UI.selection == 0) {
                helpCommand(player)
            }
            if (UI.selection == 1) {
                helpServer(player)
            }
        })
}
function helpCommand(player) {
    const UI = new ActionFormData()
        .title(`§6______§f常用命令§6______§r`)
        .body(config.text.aboutCommand)
        .button(`返回主页`)
        .button(`关闭表单`)
        .show(player)
        .then((UI) => {
            if (UI.selection == 0) {
                NewPlayerMenu(player)
            }
        })
};
function helpServer(player) {
    const UI = new ActionFormData()
        .title(`§6______§f关于本服§6______§r`)
        .body(config.text.aboutServer)
        .button(`返回主页`)
        .button(`关闭表单`)
        .show(player)
        .then((UI) => {
            if (UI.selection == 0) {
                NewPlayerMenu(player)
            }
        })
}